﻿/**
<code>
  <author name="Zealic" email="zealic(at)gmail.com" type="Creator"/>
</code>
**/
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.InteropServices;

using Zealib.Extensions;


namespace Zealib.Win32.Extensions
{
    /// <summary>
    /// Extensions for <seealso cref="System.Diagnostics.Process"/> class.
    /// </summary>
    public static class ProcessExtensions
    {
        #region PInvoke define
        [DllImport("kernel32.dll", EntryPoint = "GetProcessIoCounters", SetLastError = true)]
        private static extern bool nGetProcessIoCounters(
            IntPtr hProcess,
            out IOCounters lpIoCounters);

        #endregion

        public static IOCounters GetIOCounters(this Process self)
        {
            self.IsNotNull();
            IOCounters counters;
            if (!nGetProcessIoCounters(self.Handle, out counters))
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }
            return counters;
        }

        public static double GetCpuUsage(this Process self)
        {
            self.IsNotNull();
            //TODO: This feature not implement.
            throw new NotImplementedException();
        }

    }

}
